<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>WpDatexServer - Check database</title>
</head>
<body>
  <h2>WpDatexServer - Check database</h2>
  <a href="../../index.html">Back to Tests</a>
  <ol>
  <?php
    $_host = 'localhost';
    $_db = 'wp';
    $_user = 'wp';
    $_password = 'wp';
    $_table = 'tester';
    
    print('<li>Using database host: '.$_host.'</li>');
    print('<li>Using database: '.$_db.'</li>');
    print('<li>Using user: '.$_user.'</li>');
    print('<li>Using database table: '.$_table.'</li>');
    
    print('<li>Connect to database...</li>');
    $c = mysql_connect($_host, $_user, $_password);
    if (!$c) {
      print('<li>Connection failed. Test stopped.</li>');
      print('</ol></body></html>');
      die;
    }
    print('<li>... established!</li>');
    
    print('<li>Has database?</li>');
    if (!@mysql_select_db($_db, $c)) {
      print('<li>Database not found. Try creating...</li>');      
      if (!mysql_query('CREATE DATABASE wp')) {
        print('<li>... not successfull. Test stopped.</li>');
        print('</ol></body></html>');
        die;
      } else {
        print('<li>... successfull.</li>');
        mysql_select_db($_db, $c);    
      }
    } else {
      print('<li>Database found</li>'); 
    }
    
    $r = mysql_query('SHOW TABLES');
    $found = false;
    while ($row = mysql_fetch_array($r)) {
      if ($row[0] === $_table) {
        $found=true; break;
      }
    }
    mysql_free_result($result);
    
    if (!$found) {
      if (!mysql_query('CREATE TABLE  `'.$_table.'` ('.
        '`id` int(11) NOT NULL AUTO_INCREMENT,'.
        '`field1` varchar(255) NOT NULL,'.
        '`field2` float NULL,'.
        '`field3` text NULL,'.
        'PRIMARY KEY (id)'.
        ') ENGINE=MyISAM DEFAULT CHARSET=latin1'
      )) {
        print('<li>Table not found. Try to create ... failed. Test stopped.</li>');
        print('</ol></body></html>');
        die;
      } else {
        print('<li>Table not found. Try to create ... successfull.</li>');
      }
    } else {
      print('<li>Table found.</li>');
    }
    
    if (!mysql_query('TRUNCATE '.$_table)) {
      print('<li>Trying to empty the table ... failed. Test stopped.</li>');
      print('</ol></body></html>');
      die;
    }
    
    print('<li>Trying to empty the table ... successfull.</li>');
    ?>
  
  



</body>
</html>